﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Compression;
using System.IO;

namespace SpiderServer
{
	internal class GZip
	{
		public static void Compress(Stream source, Stream dest)
		{
			using (GZipStream zipStream = new GZipStream(dest, CompressionMode.Compress, true))
			{
				byte[] buf = new byte[1024];
				int len;
				while ((len = source.Read(buf, 0, buf.Length)) > 0)
				{
					zipStream.Write(buf, 0, len);
				}
			}
		}

		// 解压
		public static void Decompress(Stream source, Stream dest)
		{
			using (GZipStream zipStream = new GZipStream(source, CompressionMode.Decompress, true))
			{
				byte[] buf = new byte[1024];
				int len;
				while ((len = zipStream.Read(buf, 0, buf.Length)) > 0)
				{
					dest.Write(buf, 0, len);
				}
			}
		}
	}
}
